<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'
import {mRequest} from '@/utils/request'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      stepsConfig: {
        steps: [
          {
            Attrs: ['modelInfoId', 'modelShelfId','outType'],
            title: '步骤1',
            description: '选择模具类型和架号',
            nextFunc: () => {
              mRequest('modelApi/getModelInfoByShelfNoAndModelId', {
                modelShelfId: this.dataForm.modelShelfId,
                modelInfoId: this.dataForm.modelInfoId
              }, ({data}) => {
                const modelInfo = this.R.propOr({}, 'modelInfo', data)
                this.dataFormConfig['successMo']['max'] = this.R.propOr(0, 'successMo', modelInfo)
                this.dataFormConfig['primaryMo']['max'] = this.R.propOr(0, 'primaryMo', modelInfo)
                this.dataFormConfig['menTou']['max'] = this.R.propOr(0, 'menTou', modelInfo)
                this.dataFormConfig['louDou']['max'] = this.R.propOr(0, 'louDou', modelInfo)
                this.dataFormConfig['kouZi']['max'] = this.R.propOr(0, 'kouZi', modelInfo)
                this.dataFormConfig['xinZi']['max'] = this.R.propOr(0, 'xinZi', modelInfo)
                this.dataFormConfig['qiTou']['max'] = this.R.propOr(0, 'qiTou', modelInfo)
                this.dataFormConfig['jiaZi']['max'] = this.R.propOr(0, 'jiaZi', modelInfo)
                this.dataFormConfig['lengQue']['max'] = this.R.propOr(0, 'lengQue', modelInfo)
              })
            }
          },
          {
            title: '步骤2',
            description: '选择物料数量',
            Attrs: ['successMo', 'primaryMo', 'menTou', 'louDou', 'kouZi', 'xinZi', 'qiTou', 'qianPian', 'lengQue']
          },
          {title: '步骤3', description: '完成剩余内容'}
        ]
      },
      dataFormConfig: {
        id: {
          hidden: true
        },
        modelInfoId: {
          label: '模具',
          type: 'list',
          list: [],
          filterable: true,
          clearable: true,
          placeholder: '请选择模具',
          selectCallback: this.modelIdSelectCallback,
        },
        modelShelfId: {
          label: '架号',
          type: 'list',
          filterable: true,
          clearable: true,
          list: [],
          placeholder: '请输入架号'
        },
        outType:{
          label: '出库类型',
          type: 'radio',
          radioBorder: true,
          radioList: [
            {text: '报废', label: 0},
            {text: '客户调走', label: 1},
            {text: '外发打样', label: 2},
            {text: '外发做货', label: 10}
          ],
          default: 0
        },
        successMo: {
          label: '成模数量',
          type: 'number',
          max: 1000,
          selectCallback: this.successMoChangedHandle,
          default: 0
        },
        primaryMo: {
          label: '初模数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        menTou: {
          label: '闷头数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        louDou: {
          label: '漏斗数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        kouZi: {
          label: '口子数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        xinZi: {
          label: '芯子数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        qiTou: {
          label: '气头数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        qianPian: {
          label: '钳片数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        lengQue: {
          label: '冷却数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        clientName: {
          label: '客户名称',
          placeholder: '请输入客户名称'
        },
        recipientPeople: {
          label: '提货人',
          placeholder: '请输入提货人'
        },
        handlingPeople: {
          label: '模具经手人',
          placeholder: '请输入模具经手人'
        },
        deliveryMethod: {
          label: '发货方式',
          placeholder: '请输入发货方式'
        },
        dayTime: {
          label: '日期',
          type: 'date',
          placeholder: '请选择日期'
        },
        remark: {
          inputType: 'textarea',
          label: '备注',
          placeholder: '请输入备注'
        },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0
      this.initModelInfoList()
      this.initShelfList()

      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        stepsConfig: this.stepsConfig,
        dataRule: this.getNeedDataRule('modelInfoId','outType',  'dayTime', 'deliveryMethod', 'status'),
        initApi: 'modelApi/modelOutInfo',
        saveApi: 'modelApi/saveModelOut',
        updateApi: 'modelApi/updateModelOut',
        objectName: 'modelOut'
      })
    },
    successMoChangedHandle() {
      this.dataForm.successMo = this.dataForm.successMo || 0

      this.dataForm.primaryMo = this.dataForm.successMo
  //    this.dataForm.jiaZi = this.dataForm.successMo
      this.dataForm.kouZi = this.dataForm.successMo
//      this.dataForm.lengQue = this.dataForm.successMo
      this.dataForm.louDou = this.dataForm.successMo
      this.dataForm.menTou = this.dataForm.successMo
      this.dataForm.qiTou = this.dataForm.successMo
      this.dataForm.xinZi = this.dataForm.successMo
    },
    modelIdSelectCallback() {

      mRequest('modelApi/modelInfoInfo', {id: this.dataForm.modelInfoId}, (res) => {
        const {data} = res
        const {modelInfo} = data
        const {shelfId} = modelInfo
        this.dataForm.modelShelfId = shelfId

      })
    },
  }
}
</script>
